package com.jfsnpm.jfsnpm.core.web.controller;

import java.util.List;

import com.jfinal.core.Controller;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record;
import com.jfsnpm.jfsnpm.core.util.AppHelper;

public class LookupController extends Controller {
	public void role(){
		String id = getPara("id");
		String name = getPara("name");
		if(AppHelper.isEmpty(id)) id = "id";
		if(AppHelper.isEmpty(name)) name = "name";
		setAttr("id",id);
		setAttr("name",name);
	}
	public void role_get(){
		String id = getPara("id");
		String name = getPara("name");
		if(AppHelper.isEmpty(id)) id = "id";
		if(AppHelper.isEmpty(name)) name = "name";
		List<Record> list = Db.find("SELECT * FROM jfsnpm_role");
		for(Record item:list){
			item.set("render", "{"+id+":'"+item.getStr("id")+"',"
					+name+":'"+item.getStr("name")+"'}");
		}
		renderJson(list);
	}
	public void user(){
		String id = getPara("id");
		String userNo = getPara("userNo");
		String userName = getPara("userName");
		String add = getPara("add");
		if(AppHelper.isEmpty(id)) id = "id";
		if(AppHelper.isEmpty(userNo)) userNo = "userNo";
		if(AppHelper.isEmpty(userName)) userName = "userName";
		if(AppHelper.isEmpty(add)) add = "false";
		setAttr("id",id);
		setAttr("userNo",userNo);
		setAttr("userName",userName);
		setAttr("add",add);
	}
	public void user_get(){
		String id = getPara("id");
		String userNo = getPara("userNo");
		String userName = getPara("userName");
		if(AppHelper.isEmpty(id)) id = "id";
		if(AppHelper.isEmpty(userNo)) userNo = "userNo";
		if(AppHelper.isEmpty(userName)) userName = "userName";
		List<Record> list = Db.find("SELECT * FROM jfsnpm_user");
		for(Record item:list){
			item.set("render", "{"+id+":'"+item.getStr("id")+"',"
					+userNo+":'"+item.getStr("userNo")+"',"
					+userName+":'"+item.getStr("userName")+"'}");
		}
		renderJson(list);
	}
}
